package com.jjkj.environmental.environmental.presenter

import com.jjkj.environmental.environmental.bean.model.CarInfo
import com.jjkj.environmental.environmental.bean.model.CheckStation
import com.jjkj.environmental.environmental.model.NetWorkModel
import com.jjkj.environmental.environmental.presenter.base.BasePresenter
import com.jjkj.environmental.environmental.utils.MyLog
import com.jjkj.environmental.environmental.view.MainView
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import javax.inject.Inject

class MainPresenter : BasePresenter<MainView>() {
    @Inject
    lateinit var netWorkModel: NetWorkModel

    override fun initInject() {
        getComponent().inject(this)
    }


    fun loadCatList(checkStation: CheckStation) {
        netWorkModel.loadCatList(checkStation = checkStation, observer = object : Observer<List<CarInfo>> {
            override fun onComplete() {
                MyLog.i("LoginPresenter", "onComplete")
            }

            override fun onSubscribe(d: Disposable) {
                bindRxLife(d)
            }

            override fun onNext(t: List<CarInfo>) {
                getMvpView().onDataLoad(t)
            }

            override fun onError(e: Throwable) {
                getMvpView().showException(e)
                MyLog.i("LoginPresenter", "onError")
            }
        })

    }
}